package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据categoryId查询菜品记录
     * @param categoryId
     * @return
     */
    @Select("select count(*) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Integer categoryId);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> getAll(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */

    DishVO selectById(Long id);

    /**
     * 根据分类id查询菜品
     * @param dish
     * @return
     */

    List<DishVO> selectByCategoryId(Dish dish);

    /**
     * 根据id修改菜品
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    void delete(List<Long> ids);

    @Select("select d.*\n" +
            "from dish d,setmeal_dish sd, setmeal s where d.id = sd.dish_id and s.id = sd.setmeal_id and setmeal_id = #{id};")
    List<Dish> selectBySetmealId(Long id);

    /**
     * 根据套餐id查找菜品列表
     * @param id
     * @return
     */
    List<DishItemVO> getDishItemById(Long id);
}
